<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>


<script>

  function ajax(ms) {
    return new Promise((resolve, reject) => {
      setTimeout(function () {
        resolve({
          code: 200,
          data: [{}, {}]
        })
      }, ms)
    })
  }
  // async function getList() {
  const getList = async () => {
    try {
      // success
      // await ajax(3000).then(res => {
      //   console.log(res)
      // })
      // console.log(await ajax(3000)) // then
      const res = await ajax(3000)
      console.log(res)
      console.log('我是ajax后的console')
      // throw new Error('error')
      // console.log(hhha.hahha)
      await ajax(1000)
      console.log('我是ajax后的console')
    } catch (e) {
      // error
      console.log(e)
    } finally {
      //
    }
    /*
    // await ajax(3000)
    console.log('我是ajax后的console')
    await ajax(2000)
    // throw new Error('error') // 主动抛出一个js的错误
    console.log('我是ajax后的console=========')
    return 123*/
  }

  getList()
  /*
  getList().then(res => {
    console.log(res)
  }).catch(e => {
    console.log(e)
  })*/
  /*
  function getList() {
    ajax(3000).then(() => {
      console.log('我是ajax后的console')
      ajax(2000).then(() => {
        console.log('我是ajax后的console')
      })
    })

  }*/

  /*
  axios({
    url: '/ajax'
  }).then(res => {
    axios({
      url: '/ajax'
    }).then(res => {
      axios({
        url: '/ajax'
      }).then(res => {

      })
    })
  })

  new Promise((resolve, reject) => {
    // ajax
  }).then(() => {
    // new Promise()
  })*/
</script>
</body>
</html>